/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.bo.cd.impl;

import who.tmap.bo.cd.CDTypes;
import who.tmap.bo.cd.CartographicDisplay;
import who.tmap.common.TMapException;
import who.tmap.common.TMapFactory;
import who.tmap.bo.cd.point.impl.CDPointBasicImpl;
import who.tmap.bo.cd.point.impl.CDPointDataDrivenEntryImpl;
import who.tmap.bo.cd.point.impl.CDPointDataDrivenSizeImpl;
import who.tmap.bo.cd.point.impl.CDPointDataDrivenSymbolAndSizeImpl;
import who.tmap.bo.cd.point.impl.CDPointDataDrivenSymbolImpl;

public class CartographicDisplayFactory implements TMapFactory, CDTypes {

    private static CartographicDisplayFactory instance =null;
    
    /**
     * Private constructor because it is a singleton
     *
     */
    private CartographicDisplayFactory() {
    }
    
    /**
     * Lazy instanciation of the factory instance
     * @return
     */
    public static synchronized CartographicDisplayFactory getInstance() {
        if ( instance == null ) {
            instance =new CartographicDisplayFactory();
        }
        
        return instance;
    }
    
    /**
     * Instanciates cartographic display objects
     * @param bizObjectType
     * @return
     * @throws TMapException
     * @throws TMapException
     */
    public CartographicDisplay get( int cdObjectType ) throws TMapException {
    	CartographicDisplay cdObject =null;
        
        switch( cdObjectType ) {        		
        	case COLOR_PATTERN:
        	    cdObject =new CDColorPatternImpl();
        	    break;            		
        
        	case PROPORTIONAL_SYMBOLS:
        	    cdObject =new CDProportionalSymbolsImpl();
        	    break;        	    
        	    
        	case DOT_DENSITY:
        		cdObject =new CDDotDensityImpl();
        		break;
        		
        	case POINT_BASIC:
        		cdObject =new CDPointBasicImpl();
        		break;
        		
        	case POINT_DATA_DRIVEN_SIZE:
        		cdObject =new CDPointDataDrivenSizeImpl();
        		break;   
        		
        	case POINT_DATA_DRIVEN_SYMBOL:
        		cdObject =new CDPointDataDrivenSymbolImpl();
        		break;       
        		
        	case POINT_DATA_DRIVEN_SYMBOL_AND_SIZE:
        		cdObject =new CDPointDataDrivenSymbolAndSizeImpl();
        		break;          		
        	    
        	/**
        	 * ColorPatternRange is not a Cartographic display
        	 * It is here for convenience purpose only
        	 */ 
        	case COLOR_PATTERN_RANGE:
        		cdObject =new ColorPatternRangeImpl();
        		break;
        		
            	/**
            	 * CDPointDataEntry is not a Cartographic display
            	 * It is here for convenience purpose only
            	 */         		
        	case POINT_DATA_DRIVEN_ENTRY:
        		cdObject =new CDPointDataDrivenEntryImpl();
        		break;
        	            	    
        	default:
        	    throw new TMapException( "Invalid cartographic display object type [" + cdObjectType + "]" );
        
        }
        
        cdObject.setType( cdObjectType );
        
        return cdObject;
    }	
	
}
